<template>
  <common-table
    ref="table"
    :show-toolbar="false"
    @vue:mounted="() => $refs.table.load()"
    :fetch="getDataAsync"
    :fetch-params="apiParams"
    :columns="columns"
    style="width: 100%; height: 100%"
  >
    <template #index="{ index }">
      <span>{{ index + 1 }}</span>
    </template>
  </common-table>
</template>

<script>
import CommonTable from '@gis/lib/components/vex-table/index.vue';
export default {
  name: 'live-info',
  components: { CommonTable },
  props: {
    data: { type: Object, default: () => ({}) },
  },
  data() {
    return {
      columns: [
        {
          title: '操作时间',
          dataIndex: 'gmt_create',
          ellipsis: true,
          width: 180,
        },
        {
          title: '房间地址',
          dataIndex: 'residence',
          ellipsis: true,
        },
        {
          title: '类型',
          dataIndex: 'is_checkin',
          ellipsis: true,
          customRender: (v) => (v ? '迁入' : '迁出'),
          width: 80,
        },
        {
          title: '操作人',
          dataIndex: 'creator_name',
          ellipsis: true,
          width: 120,
        },
        {
          title: '与户主关系',
          dataIndex: 'relation',
          width: 120,
        },
      ],
    };
  },
  computed: {
    apiParams() {
      return { people_id: this.data.people_id };
    },
  },
  methods: {
    async getDataAsync(params) {
      if (!params || !params.people_id) return;
      const res = await this.$axios.get('/xw-microservice/xw-actual-data/v3/log/immigration/emigration/page', {
        params,
      });
      const data = res.data || {};
      return { data: data.list, total: data.count };
    },
  },
};
</script>

<style scoped lang="less"></style>
